package com.ruandi.bean;

import java.util.Random;

public class Test08 {
    public static void main(String[] args) {
        //定义一个长度为5的数组
        Rectangle[] rectangles = new Rectangle[5];
        //随机数
        Random r = new Random();
        for (int i = 0; i < rectangles.length; i++) {
            double length = 1 + 9 * r.nextDouble();
            double width = 1 + 9 * r.nextDouble();
            rectangles[i] = new Rectangle(length, width);
        }

        System.out.println("----------------排序之前---------------");
        for (Rectangle rectangle : rectangles) {
            rectangle.getInfo();
        }
        //排序之后
        System.out.println("-------------------------------------");
        System.out.println("----------------排序之后---------------");
        //冒泡排序
        for (int i = 0; i < rectangles.length - 1; i++) {
            //循环控制最值
            for (int j = 0; j < rectangles.length - 1 - i; j++) {
                if (rectangles[j].getArea() > rectangles[j + 1].getArea()) {
                    Rectangle temp = rectangles[j + 1];
                    rectangles[j + 1] = rectangles[j];
                    rectangles[j] = temp;
                }
            }
        }
        for (Rectangle rectangle : rectangles) {
            rectangle.getInfo();
        }
        System.out.println("-------------------------------------");

    }

}
